{include file='common/head'}

<div style="overflow-x: hidden;width: 96%;margin: auto;padding-top: 1rem;">
    <blockquote class="layui-elem-quote layui-text">
        <div class="demoTable layui-form">
            <div class="layui-input-inline">
                <input type="text" placeholder="请输入项目名称" name="name" class="layui-input">
            </div>
            <div class="layui-input-inline">
                <select name="admin_id"  lay-search>
                    <option value="">筛选项目负责人</option>
                    {foreach $info as $v}
                    <option value="{$v.id}">{$v.admin_name}</option>
                    {/foreach}
                </select>
            </div>
            <div class="layui-input-inline">
              <input type="text" id="start_time" name="start_time" autocomplete="off" placeholder="项目开始时间" class="layui-input">
            </div>
            <div class="layui-input-inline">
              <input type="text" id="end_time" name="end_time" autocomplete="off" placeholder="项目结束时间" class="layui-input">
            </div>
            <button class="layui-btn " data-type="reload"><i class="layui-icon">&#xe615;</i>搜索</button>
            <button class="layui-btn addInfo" style="margin:0;"><i class="layui-icon">&#xe654;</i> 添加</button>
        </div>
    </blockquote>


    <div class="demoTable layui-for">
        <table class="layui-table" lay-data="{height: 'full-100', url:'{:url('admin/Project/getList')}', page:true,id:'tableId',loading:true}" lay-filter="tableFilter">
            <thead>
            <tr>
                <th lay-data="{field:'id',width:70,fixed: true,templet:'#id',sort:true}">编号</th>
                <th lay-data="{field:'project_name',templet:'#project_name',width:170}">项目名称</th>
                <th lay-data="{field:'project_desc',templet:'#project_desc',width:170}">项目描述</th>
                <th lay-data="{field:'project_start',width:170,templet:'#project_start'}">项目开始时间</th>
                <th lay-data="{field:'project_end',templet:'#project_end',width:170}">项目结束时间</th>
                <th lay-data="{field:'project_man',width:170, templet: '#project_man'}">项目预计人数</th>
                <th lay-data="{field:'admin_name',width:170, templet: '#admin_name'}">项目负责人</th>
                <th lay-data="{field:'cycle',width:170, templet: '#cycle'}">项目周期</th>
                <th lay-data="{field:'add_time',width:170, templet: '#add_time'}">项目添加时间</th>
                <th lay-data="{fixed: '', width:180,fixed: 'right',  toolbar: '#barDemo'}">操作</th>
            </tr>
            </thead>
        </table>
        <!--操作功能-->
        <script type="text/html" id="barDemo">
            <a title="编辑" lay-event="edit" href="#"><i class="layui-icon" style="font-size: 25px; color:#029587;line-height: 30px">&#xe642;</i></a>
            <a title="删除" lay-event="delete" href="#"><i class="layui-icon" style="font-size: 25px; color:#029587;line-height: 30px">&#xe640;</i></a>
        </script>

        <!--列-自定义-->

    </div>
    <script src="/static/admin/jquery.js"></script>
    <script type="text/javascript" src="/static/index/layer/layer.js"></script>
    <script type="text/html" id="id">
        <span>{{d.id}}</span>
    </script>
    <script type="text/html" id="project_name">
        <span>{{d.project_name}}</span>
    </script>
    <script type="text/html" id="project_desc">
        <span>{{d.project_desc}}</span>
    </script>
    <script type="text/html" id="project_start">
        <span>{{d.project_start}}</span>
    </script>
    <script type="text/html" id="project_end">
        <span>{{d.project_end}}</span>
    </script>
    <script type="text/html" id="project_man">
        <span>{{d.project_man}}人</span>
    </script>
    <script type="text/html" id="admin_name">
        <span>{{d.admin_name}}</span>
    </script>
    <script type="text/html" id="add_time">
        <span>{{d.add_time}}</span>
    </script>
    <script type="text/html" id="cycle">
        <span>{{d.cycle}}天</span>
    </script>
</div>
    {include file='common/footer'}
    <!--颜色编辑-->
    <script>
        layui.use(['table','form'], function(){
            var table = layui.table
                ,form = layui.form;
            //搜索提交
            var $ = layui.$, active = {
                reload: function(){
                    var name = $('input[name="name"]').val();
                    var admin_id = $('select[name="admin_id"] option:checked').val();
                    var start_time = $('input[name="start_time"]').val();
                    var end_time = $('input[name="end_time"]').val();
                    //执行重载
                    table.reload('tableId', {
                        where: {
                            name:name,
                            admin_id:admin_id,
                            start_time:start_time,
                            end_time:end_time
                        }
                    });
                }
            };
            $('.demoTable .layui-btn').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

            //监听表格复选框选择
            table.on('checkbox(tableFilter)', function(obj){
                console.log(obj)
            });

            //表格功能
            table.on('tool(tableFilter)', function(obj){
                var data = obj.data;
                var event=obj.event;
                switch(event){
                    case 'edit':
                        layer.open({
                            type: 2,
                            title: '编辑更新数据信息',
                            shadeClose: true,
                            shade: false,
                            maxmin: true, //开启最大化最小化按钮
                            area: ['100%', '100%'],
                            content: '{:url("admin/Project/editProjectPage")}?project_id='+data.id,
                            end: function () {
                                table.reload('tableId');
                            },
                        });
                        break;
                    case 'delete':
                        layer.confirm('确定删除么?', function(index){
                            $.ajax({
                                url:'{:url("admin/Project/deleteProject")}',
                                type:'post',
                                dataType:'json',
                                data: {'id':data.id},
                                success:function(val){
                                    if(val.code == 200){
                                        obj.del();
                                        layer.msg(val.msg);
                                    }
                                    if(val.code == 400){
                                        layer.msg(val.msg);
                                    }
                                }
                            });

                        });
                        break;
                }
            });

//      添加信息 url跳转路径
            var url='{:url("Project/addProjectPage")}';
            $('.addInfo').on('click', function() {
                layer.open({
                    type: 2,
                    title: '添加内容信息',
                    shadeClose: true,
                    shade: false,
                    maxmin: true,
                    area: ['100%', '100%'],
                    content: url,
                    end: function () {
                        table.reload('tableId');
                    },
                });
            });
        });
    </script>
    <script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        var endDate= laydate.render({
            elem: '#end_time',//选择器结束时间
            type: 'datetime',
            min:"1970-1-1",//设置min默认最小值
            done: function(value,date){
                startDate.config.max={
                    year:date.year,
                    month:date.month-1,//关键
                    date: date.date,
                    hours: 0,
                    minutes: 0,
                    seconds : 0
                }
            }
        });
        //日期范围
        var startDate=laydate.render({
            elem: '#start_time',
            type: 'datetime',
            max:"2099-12-31",//设置一个默认最大值
            done: function(value, date){
                endDate.config.min ={
                    year:date.year,
                    month:date.month-1, //关键
                    date: date.date,
                    hours: 0,
                    minutes: 0,
                    seconds : 0
                };
            }
        });

    });
</script>
    </body>
    </html>